package org.example.excel;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.List;

public class ExportExcelDemo {
    private static String excelFilePath = "E:\\work_template\\" + System.currentTimeMillis() + ".xlsx";
    public static void main(String[] args) {
        try (HSSFWorkbook workbook = new HSSFWorkbook()) {
            HSSFSheet sheet = workbook.createSheet("sheet1");
            sheet.setDefaultColumnWidth(15);

            HSSFRow row1 = sheet.createRow(1);
            HSSFCellStyle headerStyle = workbook.createCellStyle();
            headerStyle.setAlignment(HorizontalAlignment.CENTER);
            headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            Font font = workbook.createFont();
            font.setColor(IndexedColors.BLACK.index);
            font.setBold(true);
            headerStyle.setFont(font);
            headerStyle.setBorderBottom(BorderStyle.THIN);
            headerStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());

            headerStyle.setBorderLeft(BorderStyle.THIN);
            headerStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());

            headerStyle.setBorderTop(BorderStyle.THIN);
            headerStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());

            headerStyle.setBorderRight(BorderStyle.THIN);
            headerStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
            row1.setHeightInPoints(36.00f);




            HSSFCell cell0 = row1.createCell(0);
            cell0.setCellStyle(headerStyle);
            cell0.setCellValue("姓名");


            HSSFCell cell1 = row1.createCell(1);
            cell1.setCellStyle(headerStyle);
            cell1.setCellValue("性别");

            HSSFCell cell2 = row1.createCell(2);
            cell2.setCellStyle(headerStyle);
            cell2.setCellValue("年龄");

            HSSFCell cell3 = row1.createCell(3);
            cell3.setCellStyle(headerStyle);
            cell3.setCellValue("联系方式");

            HSSFCell cell4 = row1.createCell(4);
            cell4.setCellStyle(headerStyle);
            cell4.setCellValue("考生号");

            HSSFCell cell5 = row1.createCell(5);
            cell5.setCellStyle(headerStyle);
            cell5.setCellValue("所属考试");

            HSSFCell cell6 = row1.createCell(6);
            cell6.setCellStyle(headerStyle);
            cell6.setCellValue("家庭地址或单位");

            HSSFCell cell7 = row1.createCell(7);
            cell7.setCellStyle(headerStyle);
            cell7.setCellValue("身份证号");

            HSSFCell cell8 = row1.createCell(8);
            cell8.setCellStyle(headerStyle);
            cell8.setCellValue("第几次来电");

            HSSFCell cell9 = row1.createCell(9);
            cell9.setCellStyle(headerStyle);
            cell9.setCellValue("来电时间");

            HSSFCell cell10 = row1.createCell(10);
            cell10.setCellStyle(headerStyle);
            cell10.setCellValue("反映的主要问题");

            sheet.createFreezePane(0,1,0,1);
            try (OutputStream stream = new FileOutputStream(new File(excelFilePath))) {
                workbook.write(stream);
            } catch (Exception e) {
            }
        } catch (Exception e) {
        }
    }
}
